package com.example.gun;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnLongClickListener;
import android.widget.ProgressBar;

/**
 * @author Robert
 * 
 */

public class MainActivity extends Activity implements GameEventListener {
	private ProgressBar pressbar;

	private boolean press=true;
	MediaPlay media;
	ShakeSever sever;
	Vibrating vib;

@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		media = new MediaPlay(this);
		sever = new ShakeSever();
		sever.init(this, this);
		vib = new Vibrating();
		pressbar = (ProgressBar) findViewById(R.id.press);
		pressbar.setOnLongClickListener(new OnLongClickListener() {

			public boolean onLongClick(View v) {

				press = true;
				return true;
			}
		});
		pressbar.setOnFocusChangeListener(new OnFocusChangeListener() {

			public void onFocusChange(View v, boolean hasFocus) {
				if (v != pressbar)
					press = false;

			}
		});
	}


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	public void Operator(GameOperatorEvent e) {
		if (press) {
			switch (e.getType()) {
			case OPEN_FIRE:
				vib.vibrate(this);
				media.playMusicShootAGun(this);
				break;
			case RELOAD:
				media.playB14Change(this);
				break;
			}
		}
	}

}
